package nl.ViewerServer.Webservice;

import java.awt.Dimension;
import java.util.ArrayList;

import nl.ViewerServer.Database.Objects.ParameterValue;
import nl.ViewerServer.ServerManager.DataManager.DataObjects.Bounds;
import nl.ViewerServer.ServerManager.DataManager.DataObjects.DataObject;
import nl.ViewerServer.ServerManager.DataManager.DataObjects.ImageDataObject;
import nl.ViewerServer.ServerManager.DataManager.DataObjects.ZoomifyDataObject;
import nl.ViewerServer.ServerManager.DataManager.Objects.LookmarkInfo;
import nl.ViewerServer.ServerManager.DataManager.Objects.Parameter;
import nl.ViewerServer.SessionManager.Objects.Job;
import nl.ViewerServer.SessionManager.Objects.Session;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class XMLUtil {
   public static String SessionArrayListToXML( ArrayList<Session> sessions ) {
      // is this necessary to prevent concurrent modification exceptions?
      ArrayList<Session> localArray = new ArrayList<Session>( sessions );
      XStream xstream = new XStream( new DomDriver() );
      xstream.setMode( XStream.NO_REFERENCES );
      // xstream.alias("Instance", Instance.class);
      xstream.alias( "Session", Session.class );
      xstream.alias( "Job", Job.class );
      String output = xstream.toXML( localArray );
      return output;
   }

   public static String ParameterArrayListToXML( ArrayList<Parameter> parameters ) {
      XStream xstream = new XStream( new DomDriver() );
      xstream.alias( "Parameter", Parameter.class );
      String output = xstream.toXML( parameters );
      return output;
   }

   public static String LookmarkInfoArrayListToXML( ArrayList<LookmarkInfo> lookmarks ) {
      XStream xstream = new XStream( new DomDriver() );
      xstream.alias( "LookmarkInfo", LookmarkInfo.class );
      String output = xstream.toXML( lookmarks );
      return output;
   }

   public static String ParameterValueArrayListToXML( ArrayList<ParameterValue> parameters ) {
      XStream xstream = new XStream( new DomDriver() );
      xstream.alias( "ParameterValue", ParameterValue.class );

      xstream.alias( "DataObject", DataObject.class );
      xstream.alias( "DataObject", ZoomifyDataObject.class );
      xstream.alias( "DataObject", ImageDataObject.class );
      xstream.alias( "Bounds", Bounds.class );
      xstream.alias( "Dimension", Dimension.class );

      String output = xstream.toXML( parameters );
      return output;
   }

   public static String DataObjectToXML( DataObject object ) {
      XStream xstream = new XStream( new DomDriver() );
      xstream.alias( "DataObject", DataObject.class );
      xstream.alias( "DataObject", ZoomifyDataObject.class );
      xstream.alias( "DataObject", ImageDataObject.class );
      xstream.alias( "Bounds", Bounds.class );
      xstream.alias( "Dimension", Dimension.class );

      String output = xstream.toXML( object );
      return output;
   }

}
